//
//  OptionButton.m
//  yunyan
//
//  Created by haichuang on 2018/2/24.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "OptionButton.h"

@implementation OptionButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithTitle:(NSString *)title image:(UIImage *)image frame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        [self createViews];
        
        [_button setBackgroundImage:image forState:UIControlStateNormal];
        _titleLabel.text=title;
     
        
    }
    return self;
}



-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self=[super initWithFrame:frame]) {
        [self createViews];
    }
    
    return self;
    
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self=[super initWithCoder:aDecoder]) {
        [self createViews];
    }
    return self;
    
}


//创建视图

-(void)createViews{
    self.backgroundColor = [UIColor whiteColor];
    _button = [[UIButton alloc]init];
    WeakSelf;
    
    [self addSubview:_button];
    _button.translatesAutoresizingMaskIntoConstraints = NO;
    // 建立约束
    [_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX);
        make.top.equalTo(weakSelf.mas_top).offset(0.0);
        make.height.equalTo(@50.0);
    }];
    
    
    _titleLabel = [[UILabel alloc] init];
    [self addSubview:_titleLabel];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.font = [UIFont systemFontOfSize:15];
   
    _titleLabel.numberOfLines = 0;
    // 建立约束
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_button.mas_centerX);
        make.top.equalTo(_button.mas_bottom).offset(8.0);
   
    }];
//    _titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
    _titleLabel.font = [UIFont systemFontOfSize:14];
    _titleLabel.textColor = RGBA(51, 51,51 , 1);
    
}
@end
